<?php

declare(strict_types=1);

namespace App\Request\Report;

use App\Constants\AdRequestEventTypeEnum;
use App\Request\Request;
use Hyperf\Validation\Rule;

class ReportAdRequestReq extends Request
{
    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'appId'               => 'required|integer:strict',
            'channel'             => 'required|string',
            'version'             => 'required|string',
            'oaid'                => 'present|string',
            'sessionId'           => 'required|string', // 会话ID
            'requestId'           => 'required|string',
            'cpm'                 => 'required|integer:strict',
            'adNetworkPlatformId' => 'required',
            'adPosition'          => 'required',
            'eventType'           => [
                'required',
                Rule::in(AdRequestEventTypeEnum::values())
            ],
            'errorCode'           => 'required'
        ];
    }

    /**
     * 获取验证错误的自定义消息
     */
    public function messages(): array
    {
        return [
            'eventType.in' => "eventType 必须是有效的广告请求事件类型"
        ];
    }
}
